package com.hengpeng.msls.service.comment.impl;

import java.util.List;

import org.springframework.stereotype.Service;

import com.hengpeng.common.persist.QueryResult;
import com.hengpeng.common.persist.entity.AbstractEntity.BoolValue;
import com.hengpeng.common.persist.query.DynamicQuery;
import com.hengpeng.itfinbase.persist.Comment;
import com.hengpeng.itfinbase.persist.Comment.CommentType;
import com.hengpeng.msls.service.BaseService;
import com.hengpeng.msls.service.comment.CommentService;

@Service
public class CommentServiceImpl extends BaseService implements CommentService
{

	@Override
	public QueryResult<Comment> findCommentList(Integer currentPage, Integer pageSize, String storeId,
			CommentType commentType)
	{
		DynamicQuery query = new DynamicQuery(Comment.class);
		query.setPageIndex(currentPage);
		query.setPageSize(pageSize);
		query.eq("auditState", BoolValue.YES);
		query.eq("replyState", BoolValue.YES);
		query.eq("isHidden", BoolValue.NO);
		query.eq("isPublic", BoolValue.YES);
		query.eq("storeId", storeId);
		query.eq("commentType", commentType);
		query.desc("postTime");
		query.setIsSearchTotalCount(true);
		return portFactory.remoteQuery(query, Comment.class);
	}

	@Override
	public QueryResult<Comment> findMyCommentList(String userName, String title, CommentType type,
			BoolValue replystate, Integer currentPage, Integer pageSize)
	{
		DynamicQuery query = new DynamicQuery(Comment.class);
		query.setPageIndex(currentPage);
		query.setPageSize(pageSize);
		query.eq("commUserName", userName);
		if (title != null)
		{
			query.like("title", "%" + title + "%");
		}
		query.eq("commentType", type);
		query.eq("replyState", replystate);
		query.eq("isHidden", BoolValue.NO);

		query.desc("postTime");
		query.setIsSearchTotalCount(true);
		return portFactory.remoteQuery(query, Comment.class);
	}

	@Override
	public List<Comment> findCommentList(Integer count, String storeId)
	{
		DynamicQuery query = new DynamicQuery(Comment.class);
		query.eq("auditState", BoolValue.YES);
		query.eq("replyState", BoolValue.YES);
		query.eq("isHidden", BoolValue.NO);
		query.eq("isPublic", BoolValue.YES);
		query.eq("storeId", storeId);
		query.desc("postTime");
		query.setPageSize(count);
		return portFactory.queryList(query, Comment.class);
	}

	@Override
	public Comment getComment(Long commentId)
	{
		return portFactory.getEntityById(commentId, Comment.class);
	}

}
